import Layout from '@/layout/index.vue'

// 组件映射表 - 将字符串路径映射为实际组件
export const componentMap: Record<string, any> = {
  // Layout组件
  Layout: Layout,

  // 首页相关
  'views/Home': () => import('@/views/Home.vue'),
  'views/About': () => import('@/views/About.vue'),

  // 仪表板
  'views/dashboard/Workplace': () => import('@/views/dashboard/Workplace.vue'),
  'views/dashboard/Analysis': () => import('@/views/dashboard/Analysis.vue'),

  // 系统管理
  'views/system/User': () => import('@/views/system/User.vue'),
  'views/system/Role': () => import('@/views/system/Role.vue'),
  'views/system/Menu': () => import('@/views/system/Menu.vue'),
  'views/system/Dept': () => import('@/views/system/Dept.vue'),
  'views/system/Dict': () => import('@/views/system/Dict.vue'),

  // 内容管理
  'views/content/Article': () => import('@/views/content/Article.vue'),
  'views/content/Category': () => import('@/views/content/Category.vue'),
  'views/content/Tag': () => import('@/views/content/Tag.vue'),
  'views/content/Comment': () => import('@/views/content/Comment.vue'),

  // 开发工具
  'views/tools/Generator': () => import('@/views/tools/Generator.vue'),
  'views/tools/Build': () => import('@/views/tools/Build.vue'),
  'views/tools/Swagger': () => import('@/views/tools/Swagger.vue'),

  // 系统监控
  'views/monitor/Online': () => import('@/views/monitor/Online.vue'),
  'views/monitor/Job': () => import('@/views/monitor/Job.vue'),
  'views/monitor/Server': () => import('@/views/monitor/Server.vue'),
  'views/monitor/Cache': () => import('@/views/monitor/Cache.vue'),

  // 日志管理
  'views/log/Operation': () => import('@/views/log/Operation.vue'),
  'views/log/Login': () => import('@/views/log/Login.vue'),
  'views/log/Error': () => import('@/views/log/Error.vue'),

  // HTML5
  'views/html5/Canvas': () => import('@/views/html5/Canvas.vue'),
  'views/html5/Swiper': () => import('@/views/html5/Swipers.vue'),

  // Vuejs
  'views/vuejs/Slot': () => import('@/views/vuejs/Slot.vue'),
  'views/vuejs/Dynamicslot': () => import('@/views/vuejs/DynamicsSlot.vue'),
}

export const transformRoutes = (routes: any) => {
  return routes.map((item: any) => {
    const transformedRoute: any = {
      path: item.path,
      name: item.name,
      component: componentMap[item.component],
      meta: item.meta || {},
    }
    if (item.redirect) {
      transformedRoute.redirect = item.redirect
    }
    if (item.children && item.children.length > 0) {
      transformedRoute.children = transformRoutes(item.children)
    }
    return transformedRoute
  })
}
